<?php
class CgtrinhthuyetminhsController extends AppController {

	var $name = 'Cgtrinhthuyetminhs';
	var $helpers = array('Html','Javascript', 'Ajax');
    var $uses=array('Cgtrinhthuyetminh','Ctrinhbb','Ctrinh');
    var $components    = array('Cookie');

/*
	function index($idct) {
		$this->Cgtrinhthuyetminh->recursive = 0;
		$this->set('cgtrinhthuyetminhs', $this->paginate('Cgtrinhthuyetminh',array('Ctrinh_id'=>$idct)));
		$this->set(compact('idct'));
	}
*/
	/**
*Trang tim kiem ds can cu de them
*/

	function index() {
		$idct=$this->Cookie->read('idct');
		$this->Ctrinh->recursive=-1;
		$tenct=$this->Ctrinh->find('first',array('conditions'=>array('id'=>$idct),'fields'=>array('tenctrinh')));

		
	//	$this->set(compact('idct'));
		$bb_daco=$this->Ctrinhbb->find('list',array('conditions'=>array('ctrinh_id'=>$idct)));
		$this->Bb->recursive = -1;
		$this->set('bbs', $this->paginate('Bb',array('id'=>$bb_daco)));

		$this->set(compact('tenct'));

	}
	

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid cgtrinhthuyetminh', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('cgtrinhthuyetminh', $this->Cgtrinhthuyetminh->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Cgtrinhthuyetminh->create();
			if ($this->Cgtrinhthuyetminh->save($this->data)) {
				$this->Session->setFlash(__('The cgtrinhthuyetminh has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The cgtrinhthuyetminh could not be saved. Please, try again.', true));
			}
		}
		$ctrinhs = $this->Cgtrinhthuyetminh->Ctrinh->find('list');
		$thuyetminhs = $this->Cgtrinhthuyetminh->Thuyetminh->find('list');
		$this->set(compact('ctrinhs', 'thuyetminhs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid cgtrinhthuyetminh', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Cgtrinhthuyetminh->save($this->data)) {
				$this->Session->setFlash(__('The cgtrinhthuyetminh has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The cgtrinhthuyetminh could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Cgtrinhthuyetminh->read(null, $id);
		}
		$ctrinhs = $this->Cgtrinhthuyetminh->Ctrinh->find('list');
		$thuyetminhs = $this->Cgtrinhthuyetminh->Thuyetminh->find('list');
		$this->set(compact('ctrinhs', 'thuyetminhs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for cgtrinhthuyetminh', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Cgtrinhthuyetminh->delete($id)) {
			$this->Session->setFlash(__('Cgtrinhthuyetminh deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Cgtrinhthuyetminh was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
